var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    noMore:'暂无更多结果',
    courseArray:[],
    demandsArray:[],
    newsArray:[],
    videoArray:[],
    mechanismsArray:[],
    isFocus:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  search:function(event){
    this.setData({
      courseArray: [],
      demandsArray: [],
      newsArray: [],
      videoArray: [],
      mechanismsArray: []
    })
    wx.showToast({
      title: '请稍后',
      icon:'loading'
    })
    var that=this
    console.log(event)
    var v=event.detail.value
    wx.request({
      url: app.globalData.baseUrl+'wechat/index/search',
      data:{
        condition:v
      },
      method:'GET',
      header:{
        'cookie':'JSESSIONID='+wx.getStorageSync('sessionID')
      },
      success:function(res){
        console.log(res);
        var resData=res.data.data
        try{
          for (var i = 0; i < resData.courseCenterCourses.length; i++) {
            var id = 'courseArray[' + i + '].id'
            var name = 'courseArray[' + i + '].name'
            that.setData({
              [id]: resData.courseCenterCourses[i].id,
              [name]: resData.courseCenterCourses[i].title
            })
          }
        }catch(err){
           console.log(err)
        }
        try{
          for (var i = 0; i < resData.news.length; i++) {
            var id = 'newsArray[' + i + '].id'
            var name = 'newsArray[' + i + '].name'
            that.setData({
              [id]: resData.news[i].id,
              [name]: resData.news[i].title
            })
          }
        }catch(err){
          console.log(err)
        }
        try{ 
          for (var i = 0; i < demands.length; i++) {
            var id = 'demandsArray[' + i + '].id'
            var name = 'demandsArray[' + i + '].name'
            that.setData({
              [id]: resData.demands[i].id,
              [name]: resData.demands[i].title
            })
          }
        }catch(err){
          console.log(err)
        }
        // console.log(typeof resData.news)
        //  var demands=Object.keys(resData.demands)
        //  console.log(demands.length)
       try{
         for (var i = 0; i < resData.microVideos.length; i++) {
           var id = 'videosArray[' + i + '].id'
           var name = 'videosArray[' + i + '].name'
           that.setData({
             [id]: resData.microVideos[i].id,
             [name]: resData.microVideos[i].title
           })
         }
       }catch(err){
         console.log(err)
       }
       try{
         for (var i = 0; i < mechanisms.length; i++) {
           var id = 'mechanismsArray[' + i + '].id'
           var name = 'mechanismsArray[' + i + '].name'
           that.setData({
             [id]: resData.mechanisms[i].id,
             [name]: resData.mechanisms[i].title
           })
         }
       }catch(err){
          console.log(err)
       }
      
        
      }
    })
  },
  toCourse:function(event){
    var id=event.currentTarget.dataset.id
     wx.navigateTo({
       url: '/lesson/content/content?id='+id,
     })
  },
  toNews:function(event){
    var id=event.currentTarget.dataset.id
    wx.navigateTo({
      url: '/eduNews/newsContent/newsContent?id='+id,
    })
  },
  toVideo:function(event){
    var id=event.currentTarget.dataset.id
    wx.navigateTo({
      url: '/eduVedio/playVideo/playVideo?id='+id,
    })
  },
  toCompany:function(event){
    var id=event.currentTarget.dataset.id
    wx.navigateTo({
      url: '',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})